home *** CD-ROM | disk | FTP | other *** search
/ 9-Digit Zip Code Directory / 9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO / z4src.zip / DIDELETE.C < prev    next >
C/C++ Source or Header  |  1993-05-26  |  3KB  |  106 lines

  1. //----------------------------------------------------------------------------
  2. //                            MODULE DESCRIPTION
  3. //
  4. //  Module:    didelete.c
  5. //   Title:    Data File I/O Library
  6. //  Notice:    John M. Weeder
  7. //                 Copyright (c) 1993. All rights reserved.
  8. //             This module contains proprietary information and should be 
  9. //                treated as confidential.
  10. //
  11. //----------------------------------------------------------------------------
  12. //                           MAINTENANCE HISTORY
  13. //
  14. // $Workfile$
  15. // $Revision$
  16. //   $Author$
  17. //     $Date$
  18. //      $Log$    
  19. //
  20. //----------------------------------------------------------------------------
  21. //                             MODULE NARRATIVE
  22. //
  23. //
  24. //    This module contains code to delete a logical file entry from a data file.
  25. //
  26. //    The code in this module should be written entirely in C. 
  27. //    Do not use any C++ constructs.
  28. //
  29. //    This module is portable to:
  30. //        DOS 3.X+
  31. //        MS Windows 3.X+
  32. //        OS/2 2.X+
  33. //        OS/2 2.0 PM
  34. //        SCO UNIX.
  35. //
  36. //    The following compilers are supported:
  37. //        MSC 6.0A
  38. //        MSC/C++ 7.0
  39. //        Borland C++ 3.1 for DOS
  40. //        Borland C++ 1.0 for OS/2 2.X
  41. //        SCO UNIX cc
  42. //
  43. //----------------------------------------------------------------------------
  44. #include <di.h>
  45.  
  46.  
  47. //----------------------------------------------------------------------------
  48. //   Description:    Delete a logical file.
  49. //                          The physical file is opened and closed when finished.
  50. //                          The space allocated in the file is wasted!
  51. //    Parameters:    pcszPhysical    Physical file name
  52. //                        pcsz                Logical file name.
  53. //                        usType            File type to delete.
  54. //       Returns:    TRUE if successful.
  55. //----------------------------------------------------------------------------
  56. BOOL FN_E DioDelete(PCSZ pcszPhysical, PCSZ pcsz, USHORT usType)
  57. {
  58.     HPF hpf;
  59.     HLF hlf;
  60.     SIZET cDir;
  61.     DATADIR dir;
  62.     BOOL fUser;
  63.     BOOL fResult = FALSE;
  64.  
  65.  
  66.     if (HIUSHORT(pcszPhysical))
  67.         {
  68.         if (!DioOpenPhysical(pcszPhysical, &hpf, TRUE))
  69.             return FALSE;
  70.         fUser = FALSE;
  71.         }
  72.     else
  73.         {
  74.         hpf = LOUSHORT(pcszPhysical);
  75.         Assert(hpf >= 0 && hpf < MAX_PHYSICAL_FILES);
  76.         Assert(di.physical[hpf].fUsed);
  77.         fUser = TRUE;
  78.         }
  79.     if (!DioOpenLogical(pcsz, &hlf, usType))
  80.         goto ERROR_EXIT;
  81.  
  82.     hpf = di.logical[hlf].hpf;
  83.     cDir = di.logical[hlf].cDir;
  84.  
  85.     if (!DioCloseLogical(hlf))
  86.         goto ERROR_EXIT;
  87.  
  88.     if (!DioDirRead(hpf, cDir, &dir))
  89.         goto ERROR_EXIT;
  90.  
  91.     dir.usType = DFT_DELETED;
  92.  
  93.     if (!DioDirWrite(hpf, cDir, &dir))
  94.         goto ERROR_EXIT;
  95.  
  96.     fResult = TRUE;
  97.  
  98. ERROR_EXIT:
  99.     if (!fUser)
  100.         DioClosePhysical(hpf);
  101.     return fResult;
  102. }
  103. //----------------------------------------------------------------------------
  104. //------------------------------- End of File --------------------------------
  105. //----------------------------------------------------------------------------
  106.